package com.qfedu.empproject.controller;

import com.qfedu.empproject.entity.Emp;
import com.qfedu.empproject.service.EmpService;
import com.qfedu.empproject.service.impl.EmpServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/EditEmp")
public class EditEmpAndShowController extends HttpServlet {
    private EmpService empService = new EmpServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String id = req.getParameter("id");
        String name = req.getParameter("name");
        String salary = req.getParameter("salary");
        String age = req.getParameter("age");

        Emp emp = new Emp(Integer.valueOf(id),name,Double.valueOf(salary),Integer.valueOf(age));
        int update = empService.update(emp);
        if (1 == update){
            req.getRequestDispatcher("/showAll").forward(req,resp);
        }

    }

}
